<%--
  Created by IntelliJ IDEA.
  User: 88403
  Date: 2021/6/16
  Time: 21:23
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>

    <title>首页</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>


    <script type="text/javascript">
        function deleteAdmin(id){
            var res = confirm("是否删除");
            if(res==true){
                location.href="${pageContext.request.contextPath}/admin/deleteAdmin?id="+id;
            }
        }



    </script>
</head>
<body>
<%@include file="header.jsp"%>
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i>
                <a href="index.jsp">首页</a><span class="crumb-step">&gt;
                </span><span href="#" class="crumb-name">管理员信息</span></div>
        </div>
        <div class="result-wrap">

                <div class="result-title">
                    <div class="result-list">
                        <c:if test="${loginuser.state eq 1}">
                        <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal">增加管理员</button>&nbsp;&nbsp;
                        </c:if>
                        <c:if test="${loginuser.state eq 0}">
<%--                            <button disabled="true" type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal">增加管理员</button>&nbsp;&nbsp;--%>
                        </c:if>
                        <span><b><font color="blue">注：权限1为超级管理员，可对所有信息进行操作；权限0为普通管理员，不能对管理员信息进行操作</font></b></span>
                                <!-- 弹出模态框 -->
                        <div class="modal fade"  tabindex="-1" role="dialog" id="myModal">
                            <div class="modal-dialog" role="document" >
                                <div class="modal-content" style="height: 300px;width: 400px" >
                                    <div class="modal-header" >
                                        <button type="button" class="close" data-dismiss="modal">
                                            <span>&times;</span>
                                        </button>
                                        <h4 class="modal-title">添加管理员</h4>
                                    </div>
                                    <form action="${pageContext.request.contextPath}/admin/addAdmin" method="post" class="form-horizontal">
                                        <div class="motal-body" align="center">
                                            <table>
                                                <tr>
                                                    <td><label>用户名：</label></td>
                                                    <td><input type="text" placeholder="用户名" name="name" value=""></td>
                                                </tr>
                                                <tr>
                                                    <td><label>密码：</label></td>
                                                    <td><input type="password" placeholder="密码" name="password" value=""></td>
                                                </tr>
                                                <tr>

                                                    <td><label >权限：</label></td>
                                                    <td><select name="state" value="" >
                                                        <option selected>0</option>
                                                        <option>1</option>
                                                    </select>
                                                       </td>
                                                </tr>
                                            </table>

                                            <button type="submit" class="btn btn-primary">添加</button>

                                        </div>

                                    </form>


                                </div>
                            </div>
                        </div>


                    </div>
                </div>
                <div class="result-content">
                    <table class="result-tab" width="100%">
                        <tr>
                            <th>ID</th>
                            <th>姓名</th>
                            <th>密码</th>
                            <th>权限</th>
                            <th>操作</th>
                        </tr>
                        <c:forEach items="${pi.list}" var="admin" varStatus="i">
                        <tr>
                                <td>${i.count}</td>
                                <td>${admin.name}</td>
                                <td>${admin.password}</td>
                                <td>${admin.state}</td>
                                <td>
                                    <c:if test="${loginuser.state eq 1}">
                                    <button onclick="deleteAdmin(${admin.id})" class="btn btn-danger btn-sm">删除</button>&nbsp;&nbsp;
                                    <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal${admin.id}">修改</button>&nbsp;&nbsp;
                                    </c:if>
                                    <c:if test="${loginuser.state eq 0}">
<%--                                        <button onclick="deleteAdmin(${admin.id})" class="btn btn-danger btn-sm" disabled="true">删除</button>&nbsp;&nbsp;--%>
<%--                                        <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal${admin.id}" disabled="true">修改</button>&nbsp;&nbsp;--%>
                                    </c:if>
                                    <!-- 弹出模态框 -->

                                    <div class="modal fade"  tabindex="-1" role="dialog" id="myModal${admin.id}">
                                        <div class="modal-dialog" role="document" >
                                            <div class="modal-content" style="height: 300px;width: 400px" >
                                                <div class="modal-header" >
                                                    <button type="button" class="close" data-dismiss="modal">
                                                        <span>&times;</span>
                                                    </button>
                                                    <h4 class="modal-title">修改管理员信息</h4>
                                                </div>
                                                <form action="${pageContext.request.contextPath}/admin/updateAdmin?id=${admin.id}" method="post" class="form-horizontal">
                                                    <div class="motal-body" align="center">
                                                        <table>
                                                            <tr>
                                                                <td><label>用户名：</label></td>
                                                                <td><input type="text" placeholder="用户名" name="name" value="${admin.name}"></td>
                                                            </tr>
                                                            <tr>
                                                                <td><label>密码：</label></td>
                                                                <td><input type="password" placeholder="密码" name="password" value="${admin.password}"></td>
                                                            </tr>
                                                            <tr>
                                                                <td><label>权限：</label></td>
                                                                <td><input type="text" placeholder="权限" name="state" value="${admin.state}"></td>
                                                            </tr>
                                                        </table>

                                                        <button type="submit" class="btn btn-primary">修改</button>
                                                            <%--                                            <input  type="submit" value="修改">--%>
                                                    </div>

                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                      <%--模态框end--%>
                                </td>
                            </tr>
  </c:forEach>
                    </table>
                </div>




            <%--分页 后台传过来的分页集合为pi即可,路径根据需求修改--%>
            <div class="Pages" align="center">
                <span >目前在第<b>${pi.pageNum}</b>页,</span>
                <span class="p_count">共有<b>${pi.pages}</b>页,</span>
                <span class="p_total">本页共有<b>${pi.size}</b>条记录</span>
                <span class="p_page">
                              <a href="${pageContext.request.contextPath}/teachers/select?pageNum=1" class="a_first">首页</a>
                           <c:if test="${pi.hasPreviousPage}">
                               <a href="${pageContext.request.contextPath}/teachers/select?pageNum=${pi.pageNum-1}" class="a_prev">上一页</a>
                           </c:if>
                            <c:forEach begin="1" end="${pi.pages}" var="index">
                                <c:if test="${pi.pageNum==index}">
                                    <li class="active" style="display: inline;">
                                        <a href="${pageContext.request.contextPath}/teachers/select?pageNum=${index}" style=" line-height: 20px;color: black; text-decoration: none;padding: 10px 10px;">${index}</a>
                                    </li>
                                </c:if>
                                <c:if test="${pi.pageNum!=index}">
                                    <li class="" style="display: inline;">
                                        <a href="${pageContext.request.contextPath}/teachers/select?pageNum=${index}" style=" line-height: 20px;color: black; text-decoration: none;padding: 10px 10px;">${index}</a>
                                    </li>
                                </c:if>
                            </c:forEach>

                            <c:if test="${pi.hasNextPage}">
                                <a href="${pageContext.request.contextPath}/teachers/select?pageNum=${pi.pageNum+1}" class="a_next">下一页</a>
                            </c:if>
                             <a href="${pageContext.request.contextPath}/teachers/select?pageNum=${pi.pages}" class="a_end">末页</a>
                          </span>
            </div>
            <%-- 分页end--%>

        </div>
    </div>

    </div>
</div>
</div>
</body>
</html>
